/**
 * Copyright 2013 ABSir's Studio
 * 
 * All right reserved
 *
 * Create on 2013-6-21 下午6:58:48
 */
package com.absir.android.view;

import java.util.ArrayList;
import java.util.List;

import android.view.View;

/**
 * @author absir
 * 
 */
public class InjectExcutorObject<T> {

	/** object */
	private T object;

	/** injectExcutor */
	private InjectExcutor<T> injectExcutor;

	/** flaterViews */
	private List<View> flaterViews = new ArrayList<View>();

	/**
	 * @param object
	 * @param injectExcutor
	 */
	public InjectExcutorObject(T object, InjectExcutor<T> injectExcutor) {
		this.object = object;
		this.injectExcutor = injectExcutor;
	}

	/**
	 * @return the object
	 */
	public T getObject() {
		return object;
	}

	/**
	 * @return the injectExcutor
	 */
	public InjectExcutor<T> getInjectExcutor() {
		return injectExcutor;
	}

	/**
	 * @param flaterView
	 */
	public void addFlaterView(View flaterView) {
		flaterViews.add(flaterView);
	}

	/**
	 * @param id
	 * @param type
	 * @param name
	 * @return
	 */
	public View loadView(int id, String type, String name) {
		if (!(type == null || name == null)) {
			id = InjectViewUtils.getResouceId(id, type, name);
		}

		if (id <= 0) {
			return null;
		}

		return injectExcutor.loadView(object, id);
	}

	/**
	 * @param id
	 * @param type
	 * @param name
	 * @return
	 */
	public View findViewById(int id, String type, String name) {
		if (!(type == null || name == null)) {
			id = InjectViewUtils.getResouceId(id, type, name);
		}

		if (id <= 0) {
			return null;
		}

		View view = injectExcutor.findViewById(object, id);
		if (view == null) {
			for (View flaterView : flaterViews) {
				view = flaterView.findViewById(id);
				if (view != null) {
					break;
				}
			}
		}

		return view;
	}
}
